var lastresult = true;
var zjname = "";

$("#outerdiv").hide();
$("#shows").hide();
$("#Material").hide();
/*function imgShow(outerdiv, bigimg, _this) {
    var src = _this.attr("src");//获取当前点击的pimg元素中的src属性
    $("#outerdiv").attr("display", "block");
    $("#bigimg").attr("src", src);  //设置#bigimg元素的src属性
    $("#outerdiv").fadeIn("fast");

    $("#outerdiv").click(function () {//再次点击淡出消失弹出层
        $(this).fadeOut("fast");
    });
}*/
/*layui.use('element', function(){
    var element = layui.element;
});*/
$(function() {
	$(document).on('click', '.pic-dl', function(e) {
		var src = $(this).attr('data-src');
		var filename = src.substr(src.lastIndexOf('/') + 1);
		var canvas = document.createElement('canvas');
		var img = document.createElement('img');
		img.onload = function(e) {
			canvas.width = img.width;
			canvas.height = img.height;
			var context = canvas.getContext('2d');
			context.drawImage(img, 0, 0, img.width, img.height);
			canvas.getContext('2d').drawImage(img, 0, 0, img.width, img.height);
			canvas.toBlob((blob)=>{
				let link = document.createElement('a');
				link.href = window.URL.createObjectURL(blob);
				link.download = filename; 
				link.click();  
			}, "image/jpeg");
		}
		img.setAttribute("crossOrigin",'Anonymous');
		img.src = src;
	});
});
var vm = new Vue({
    el : "#DiyLists",
    data : {
    },
    /*photoList:{},*/
    init:function(){
        var _self = this;
        layui.use(['layer'], function(){
            layer = layui.layer;
        });


        $("#shows1").hide();

        $("#shows2").hide();
        $("#shows3").hide();

    },
    methods: {
        getPhotoByCode: function(event){
            var _self = this;
            var PhotoIds = document.getElementById("PhotoId").value;   //作业工单RFID

            if (event && (event.keyCode != 13 || !(PhotoIds && PhotoIds.length > 0))) {
                return;
            }

            _self.$nextTick(function() {
                _self.$http.post("../../DiyList/getDiyLists",{PhotoCode:PhotoIds},{emulateJSON: true}).then(function(res){
                    if(res.ok){
                        _self.DiyLists = res.body.DiyPhotolist;
                        if(res.body.DiyPhotolist.length == 0){
                            _self.vueAlert("无RFID信息！");
                            return;
                        }
                        if(_self.DiyLists[0].STATUSS != 'FINISHED'){
                            _self.vueAlert("上道工序未完工！");
                            return;
                        }

                        if(_self.DiyLists[0].ZYSTATUS == 'FINISHED'){
                            _self.vueAlert("该工序已完工！");
                            return;
                        }

                        //左脚DIY信息图片
                        /*photoList = _self.DiyLists;*/
                        var equipmentwork = "";
                        var number = 0;
                        var DiyPhotos = "";
                        var namelist = "";

                        namelist +="<input style='background:#FFFFFF; margin-top:20px;'  disabled=\"\" value='工单号:    "+_self.DiyLists[0].ZYCODE+"'/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";

                        namelist +=" <input style='background:#FFFFFF; margin-top:20px;'  disabled=\"\" value='型体:    "+_self.DiyLists[0].WLNAME+"'/>";

                        namelist +=" <input style='background:#FFFFFF; margin-top:20px;'  disabled=\"\" value='颜色:    "+_self.DiyLists[0].COLORNAME+"'/>";

                        equipmentwork += "<div class=\"layui-form-item\">";

                        for( i = 0 ; i<res.body.DiyPhotolist.length ; i++){
                            if(_self.DiyLists[i].FOOTTYPE == "LEFT"){
                                equipmentwork +="<div class='layui-inline' style=\"display:inline-block;\" >  " ;
                                equipmentwork +="<div class='layui-col-xs4' class='div_card'>" ;
                                equipmentwork +="<div class='layui-row' >";
                                equipmentwork +="<div style='width:250;float:left;' id ='outerdiv'>";
                                equipmentwork +="<img id=\"bigimg\" src='"+_self.DiyLists[i].PICPATH+"'   style=\"margin-top:10px;\" class=\"div_card_image\" name='"+i+"' >";
                                equipmentwork +="</div>";
                                equipmentwork +="</div>";
                                equipmentwork +="</div>";
                                equipmentwork +="</div>";
                                if(_self.DiyLists[i].DIYTYPE === "IMG" && _self.DiyLists[i].ICONPATH){
                                	equipmentwork +="<div class='layui-inline' style=\"display:inline-block;\" >  " ;
                                    equipmentwork +="<div class='layui-col-xs4' class='div_card'>" ;
                                    equipmentwork +="<div class='layui-row' >";
                                    equipmentwork +="<div style='width:250;float:left;' id ='outerdiv'>";
                                    equipmentwork +="<img id=\"bigimg\" src='"+_self.DiyLists[i].ICONPATH+"'   style=\"margin-top:10px;\" class=\"div_card_image\" name='"+i+"' >";
                                    equipmentwork +='<button type="button" class="layui-btn layui-btn-normal pic-dl" data-src="'+_self.DiyLists[i].ICONPATH+'">下载</button>';
                                    equipmentwork +="</div>";
                                    equipmentwork +="</div>";
                                    equipmentwork +="</div>";
                                    equipmentwork +="</div>";
                                }

                                if(_self.DiyLists[i].DIYTYPE == "FONT"){
                                    number = i;
                                }
                                
                            }

                        }
                        equipmentwork +="</div>";

                        DiyPhotos +="<div class='layui-inline'  style=\"display:inline-block; margin-left:10px;  float:left; \" >  " ;
                        DiyPhotos +="<div style=\"float:right;margin-left:10px;\">";

                        if(_self.DiyLists[number].ZTNAME == null){
                            _self.DiyLists[number].ZTNAME = "";
                        }
                        DiyPhotos +="<div class=\"div_card_name\"> <input style='background:#FFFFFF; margin-top:20px;'  disabled=\"\" value ='左脚电绣信息'/></div>";
                        DiyPhotos +="<div class=\"div_card_name\"> <input style='background:#FFFFFF; margin-top:20px;'  disabled=\"\" value='定制部位：   "+_self.DiyLists[number].BWNAME+"'/></div>";
                        DiyPhotos +="<div class=\"div_card_name\"> <input style='background:#FFFFFF; margin-top:20px;'  disabled=\"\" value='字体：   "+_self.DiyLists[number].ZTNAME+"'/></div>";
                        if(_self.DiyLists[number].YSNAME == null){
                            _self.DiyLists[number].YSNAME = "";
                        }

                        DiyPhotos +="<div class=\"div_card_name\"> <input style='background:#FFFFFF; margin-top:20px;'  disabled=\"\" value='字体颜色：   "+_self.DiyLists[number].YSNAME+"'/></div>";
                        if(_self.DiyLists[number].TEXT == null){
                            _self.DiyLists[number].TEXT = "";
                        }
                        DiyPhotos +="<div class=\"div_card_name\"> <input style='background:#FFFFFF; margin-top:20px;'  disabled=\"\"  value='字体内容：   "+_self.DiyLists[number].TEXT+"'/></div>";
                        if(_self.DiyLists[number].WEIZHI == null){
                            _self.DiyLists[number].WEIZHI = "";
                        }
                        DiyPhotos +="<div class=\"div_card_name\"> <input style='background:#FFFFFF; margin-top:20px;'  disabled=\"\" value='坐标位置:    "+_self.DiyLists[number].WEIZHI+"'/></div>";
                        DiyPhotos +="<div ></div>";
                        DiyPhotos +="</div>";
                        DiyPhotos +="</div>";

                        $("#DiyPhotoLeft").html(equipmentwork);
                        $("#DiyPhotosLeft").html(DiyPhotos);
                        $("#nameLists").html(namelist);




                        //右脚DIY信息图片
                        var RightPhoto = "";
                        var RightFoot = "";
                        var numbers = 0;
                        RightPhoto += "<div class=\"layui-form-item\">";

                        for( y = 0 ; y<res.body.DiyPhotolist.length ; y++){
                            if(_self.DiyLists[y].FOOTTYPE == "RIGHT"){
                                RightPhoto +="<div class='layui-inline' style=\"display:inline-block;\" >  " ;
                                RightPhoto +="<div class='layui-col-xs4' class='div_card'>" ;
                                RightPhoto +="<div class='layui-row' >";
                                RightPhoto +="<div style='width:250;float:left;' id ='outerdiv'>";
                                RightPhoto +="<img id=\"bigimg\" src='"+_self.DiyLists[y].PICPATH+"'   style=\"margin-top:10px;\" class=\"div_card_image\" name='"+y+"' >";
                                RightPhoto +="</div>";
                                RightPhoto +="</div>";
                                RightPhoto +="</div>";
                                RightPhoto +="</div>";
                                if(_self.DiyLists[y].DIYTYPE === "IMG" && _self.DiyLists[y].ICONPATH){
                                	RightPhoto +="<div class='layui-inline' style=\"display:inline-block;\" >  " ;
                                	RightPhoto +="<div class='layui-col-xs4' class='div_card'>" ;
                                	RightPhoto +="<div class='layui-row' >";
                                	RightPhoto +="<div style='width:250;float:left;' id ='outerdiv'>";
                                	RightPhoto +="<img id=\"bigimg\" src='"+_self.DiyLists[y].ICONPATH+"'   style=\"margin-top:10px;\" class=\"div_card_image\" name='"+y+"' >";
                                	RightPhoto +='<button type="button" class="layui-btn layui-btn-normal pic-dl" data-src="'+_self.DiyLists[y].ICONPATH+'">下载</button>';
                                	RightPhoto +="</div>";
                                	RightPhoto +="</div>";
                                	RightPhoto +="</div>";
                                	RightPhoto +="</div>";
                                }
                                if(_self.DiyLists[y].DIYTYPE == "FONT"){
                                    numbers = y;
                                }

                            }

                        }
                        RightPhoto +="</div>";

                        RightFoot +="<div class='layui-inline'  style=\"display:inline-block; margin-left:10px;  float:left; \" >  " ;
                        RightFoot +="<div style=\"float:right;margin-left:10px;\">";
                        /*RightFoot +="<button type=\"button\" class=\"layui-btn layui-btn-normal\" @click=\"showDocument\">工艺指导文件</button>";
                        RightFoot +="<button type=\"button\" class=\"layui-btn layui-btn-normal\" @click=\"abnormalReport\">异常上报</button>";*/

                        if(_self.DiyLists[numbers].ZTNAME == null){
                            _self.DiyLists[numbers].ZTNAME = "";
                        }
                        RightFoot +="<div class=\"div_card_name\"> <input style='background:#FFFFFF; margin-top:20px;'  disabled=\"\" value='右脚电绣信息'/></div>";
                        RightFoot +="<div class=\"div_card_name\"> <input style='background:#FFFFFF; margin-top:20px;'  disabled=\"\" value='定制部位：   "+_self.DiyLists[number].BWNAME+"'/></div>";
                        RightFoot +="<div class=\"div_card_name\"> <input style='background:#FFFFFF; margin-top:20px;'  disabled=\"\" value='字体：   "+_self.DiyLists[numbers].ZTNAME+"'/></div>";
                        if(_self.DiyLists[numbers].YSNAME == null){
                            _self.DiyLists[numbers].YSNAME = "";
                        }
                        RightFoot +="<div class=\"div_card_name\"> <input style='background:#FFFFFF; margin-top:20px;'  disabled=\"\" value='字体颜色：   "+_self.DiyLists[numbers].YSNAME+"'/></div>";
                        if(_self.DiyLists[numbers].TEXT == null){
                            _self.DiyLists[numbers].TEXT = "";
                        }
                        RightFoot +="<div class=\"div_card_name\"> <input style='background:#FFFFFF; margin-top:20px;'  disabled=\"\"  value='字体内容：   "+_self.DiyLists[numbers].TEXT+"'/></div>";
                        if(_self.DiyLists[numbers].WEIZHI == null){
                            _self.DiyLists[numbers].WEIZHI = "";
                        }
                        RightFoot +="<div class=\"div_card_name\"> <input style='background:#FFFFFF; margin-top:20px;'  disabled=\"\" value='坐标位置:    "+_self.DiyLists[numbers].WEIZHI+"'/></div>";
                        RightFoot +="<div ></div>";
                        RightFoot +="</div>";
                        RightFoot +="</div>";

                        $("#DiyPhotoRight").html(RightPhoto);
                        $("#DiyPhotosRight").html(RightFoot);

                        layui.use(['form', 'element'], function(){
                            form = layui.form;
                            /*var element = layui.element;*/
                            form.render(); //这个很重要
                        });

                       //  _self.showDocument();
                        $("#shows1").show();

                        $("#shows2").show();
                        $("#shows3").show();
                    }

                    /*$("img").mouseover(function(){
                        $(this).css("cursor","pointer");
                    });

                    $("img").click(function(){
                        var _this = $(this);//将当前的pimg元素作为_this传入函数
                        imgShow("#outerdiv", "#bigimg", _this);
                    });*/
                    $("#shows").show();
                });
            });



        }
        ,reset: function(data){
            window.location.reload();
        }
        ,vueAlert: function(msg){
            layui.use(['form'], function(){
                var layer = layui.layer;
                layer.msg(msg,{icon:6,time:2000});
            });
        }
        ,clearReceiveForm: function(){
            $("#reMakeNum").val('');
            $("#confirmReceiveNum").val('');
        },
        // 显示指导文件
        showDocument: function() {
            layer.open({
                type: 2,
                title: '工艺指导文件',
                shadeClose: true,
                shade: 0.8,
                area: ['90%', '90%'],
                content: "../../script/js/pdfJs/web/viewer.html?file=../../../../manNeedleCart/downFile/" + this.order //iframe的url
            });
        },
        // 异常上报
        abnormalReport: function() {
            layer.open({
                type: 2,
                title: '异常上报',
                shadeClose: true,
                shade: 0.8,
                area: ['90%', '90%'],
                content: "abnormalReport.html" //iframe的url
            });
        }


    }
});
